package com.busfm.util;

import com.busfm.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class DialogUtil {

    public static interface OnWarningDialogListener {
        public void onWarningDialogOK(int id);
    }

    public static interface OnWarningOkCanceDialogListener {
        public void onWarningDialogOK(int id);

        public void onWarningCancel(int id);
    }

    public static Dialog CreateInfoDialog(
        final Context context, final int id, String message, final OnWarningDialogListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(message);
        builder.setPositiveButton(R.string.dialog_btn_sure, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof Activity) {
                    ((Activity) context).removeDialog(id);
                }

                if (null != listener) {
                    listener.onWarningDialogOK(id);
                }
            }
        });
        return builder.create();
    }

    public static Dialog CreateInfoDialog(
        final Context context, final int id, String title, String message, final OnWarningDialogListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(message);
        builder.setTitle(title);
        builder.setPositiveButton(R.string.dialog_btn_sure, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof Activity) {
                    ((Activity) context).removeDialog(id);
                }

                if (null != listener) {
                    listener.onWarningDialogOK(id);
                }
            }
        });
        return builder.create();
    }

    public static Dialog createInfoDialog(
        final Context context, final int id, String title, String message, String positiveMsg, String negavitiveMsg,
        final OnWarningOkCanceDialogListener listener) {
        AlertDialog.Builder buider = new AlertDialog.Builder(context);
        buider.setTitle(title);
        buider.setMessage(message);
        buider.setCancelable(false);
        buider.setPositiveButton(positiveMsg, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof Activity) {
                    ((Activity) context).removeDialog(id);
                }

                if (null != listener) {
                    listener.onWarningDialogOK(id);
                }
            }
        });
        buider.setNegativeButton(negavitiveMsg, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof Activity) {
                    ((Activity) context).removeDialog(id);
                }

                if (null != listener) {
                    listener.onWarningCancel(id);
                }
            }
        });
        return buider.create();

    }
}
